package handler

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
)

func UpLoad(c *gin.Context) {
	file, _ := c.FormFile("file")
	log.Println(file.Filename)

	dst := "D:\\GO-Work\\src\\websocket_exam\\static\\upload\\" + file.Filename
	// 上传文件至指定的完整文件路径
	err := c.SaveUploadedFile(file, dst)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 100000,
			"mes":  "上传图片失败",
			"data": false,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": http.StatusOK,
		"mes":  "上传图片成功",
		"data": fmt.Sprintf("http://127.0.0.1:8080/upload" + file.Filename),
	})
}
